<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      const clearCookie = () => {
        if (!document.cookie) return;
        const keys = (document.cookie.split(";") || []).map((item) => {
          const temp = item.split("=") || [];
          return temp[0] || "";
        });
        keys.forEach((key) => {
          document.cookie = `${key}=;domain=.huawei.com;`;
        });
      };
      const baseUrl = "http://localhost.huawei.com:5500";
      let timer = null;
      const getUid = () => {
        fetch(`${baseUrl}/uid`)
          .then((res) => res.json())
          .then(({ uid }) => {
            if (timer) {
              clearTimeout(timer);
            }
            if (uid) {
              statistic(uid);
            } else {
              timer = setInterval(getUid, 100);
            }
          });
      };
      window.onload = function () {
        fetch(`${baseUrl}/userStatus`)
          .then((res) => res.json())
          .then(({ userStatus }) => {
            if (userStatus === "login") {
              fetch(`${baseUrl}/cookie`);
              return;
            }
            clearCookie();
            fetch(`${baseUrl}/login`).then(() => {
              window.open(
                `https://login.huawei.com/login?redirect=${baseUrl}/index.html`,
                "_self"
              );
            });
          });
        getUid();
      };
    </script>
    <!-- Matomo -->
    <script type="text/javascript">
      var _paq = window._paq || [];
      _paq.push(["trackPageView"]);
      _paq.push(["enableLinkTracking"]);
      function statistic(uid) {
        var u = "https://oha.rnd.huawei.com/piwik/";
        if (uid) {
          _paq.push(["setUserId", uid]);
        }
        _paq.push(["setTrackerUrl", u + "matomo.php"]);
        _paq.push(["setSiteId", "3"]);
        var d = document,
          g = d.createElement("script"),
          s = d.getElementsByTagName("script")[0];
        g.type = "text/javascript";
        g.async = true;
        g.defer = true;
        g.src = u + "matomo.js";
        s.parentNode.insertBefore(g, s);
      }
    </script>
    <!-- End Matomo Code -->
  </body>
</html>
